package com.qf.kele02.intercepto;

import com.qf.kele02.entity.User;
import com.qf.kele02.service.UserSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Author: 可乐
 * @Description:
 * @CreateTime: 2022-10-19  20:23
 */
@Component
public class MyInterceptor implements HandlerInterceptor {

	@Qualifier(value="userServicePlusImp")
	@Autowired
	UserSevice userSevice;

	@Override
	public boolean preHandle( HttpServletRequest request,HttpServletResponse response,Object handler ) throws Exception {

		//拦截器的安全控制
		HttpSession session=request.getSession( );
		User user=(User) session.getAttribute( "user" );

		if(user!=null) {
			return true;
		}

		response.sendRedirect( "login.html" );
		return false;

	}
}
